<?php
$this->pageHeader = t('LBL_VIEW_PROFILE', 'profile');
$this->pageTitle = t('PAGE_TITLE', 'profile');
$logedInUser = User::model()->findByPk(Yii::app()->user->id);
$toolbar = new LGToolbar();
$toolbar->buttonNewPage(t('BTN_EXPORT_DOCUMENT', 'profile'), '', '/translate/report', array('id' => $model->id, 'alias' => stringURLSafe($model->full_name)));
$toolbar->buttonNewPage(t('BTN_PRINT', 'profile'), '', app()->controller->id . '/print/' . $model->id);
if ($logedInUser->isEditor() || $logedInUser->isAdmin() || $logedInUser->isSuperAdmin()) {
    $toolbar->buttonNewPage(t('PAGE_TITLE_ADDNEW', 'advanceProfile'), '', 'advanceprofile/index/', array('id' => $model->id));
}

if (($logedInUser->isManager() && $model->status != ProfileStatus::STATUS_ACCEPTED && $model->status == ProfileStatus::STATUS_TRANSLATED) || $logedInUser->isAdmin() || $logedInUser->isSuperAdmin()) {
    $toolbar->buttonNewPage(t('BTN_ACCEPT', 'profile'), '', app()->controller->id . '/accept/' . $model->id);
    $toolbar->buttonNewPage(t('BTN_RETRANSLATE', 'profile'), '', app()->controller->id . '/retranslate/' . $model->id);
}

if (($logedInUser->isEditor() && ($model->status == ProfileStatus::STATUS_WAITING || $model->status == ProfileStatus::STATUS_TRANSLATING || $model->status == ProfileStatus::STATUS_WAITING_FOR_RETRANSLATE || $model->status == ProfileStatus::STATUS_TRANSLATED)) || $logedInUser->isAdmin() || $logedInUser->isSuperAdmin()) {
    $toolbar->buttonNewPage(t('BTN_EDIT_TRANSLATED', 'profile'), '', '/translate/index/', array("id" => $model->id));
    $toolbar->buttonNewPage(t('BTN_REJECT', 'profile'), '', app()->controller->id . '/reject/' . $model->id);
} else if ($logedInUser->isManager() && $model->status == ProfileStatus::STATUS_TRANSLATED) {
    $toolbar->buttonNewPage(t('BTN_REJECT', 'profile'), '', app()->controller->id . '/reject/' . $model->id);
}
$toolbar->Cancel('btnCancel', t('BTN_CANCEL'), url('/profile/'));
$this->pageToolbar = $toolbar->mergeToolbar();
$date1 = new DateTime($model->update_date);
$flagDate = 'dinvalid';
if (isset($translatedModel)) {
    $date2 = new DateTime($translatedModel->update_date);
    $flagDate = ($date1 <= $date2) ? 'dvalid' : 'dinvalid';
}
?>
<div class="moreinfo">
    <table>
        <tr>
            <td>Trạng thái: <?php echo t("STATUS_" . $model->status, "profile"); ?></td>
            <td style="width: 50px;"></td>
            <td><?php echo t("HEADER_UPDATE_DATE", "history"); ?></td>
            <td><span><?php echo $model->update_date; ?></span></td>	
            <td style="width: 50px;"></td>
            <td><?php echo t("HEADER_TRANSLATE_DATE", "history"); ?></td>
            <td><span class="<?php echo $flagDate ?>">
<?php echo (isset($translatedModel->update_date)) ? $translatedModel->update_date : 'Hồ sơ chưa được dịch lần nào'; ?>
                </span></td>
        </tr>
    </table>
</div>
<?php
unset($date1, $date2, $flagDate);
?>
<div class="profile-detail view-detail">
    <?php $this->renderPartial('_detail/__basic', array('model' => $model, 'translatedModel' => $translatedModel)); ?>
    <?php $this->renderPartial('_detail/__health', array('model' => $model)); ?>
    <?php $this->renderPartial('_detail/__family', array('model' => $model, 'translatedModel' => $translatedModel)); ?>
    <?php $this->renderPartial('_detail/__study', array('model' => $model, 'translatedModel' => $translatedModel, 'mode'=>'view')); ?>
    <?php $this->renderPartial('_detail/__working', array('model' => $model, 'translatedModel' => $translatedModel, 'mode'=>'view')); ?>
    <?php $this->renderPartial('_detail/__other', array('model' => $model, 'translatedModel' => $translatedModel, 'mode'=>'view')); ?>
    <?php $this->renderPartial('_detail/__health_checking', array('model' => $model)); ?>
    <?php
    if ($logedInUser->isTranslator() == FALSE) {
        $this->renderPartial('_detail/__advance_information', array('model' => $model));
    }
    ?>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $(".accordination").each(function () {
            $(this).find(".pdetail").first().hide();
            $(this).find(".thead").click(function () {
                if ($(this).next().css('display') == 'none')
                {
                    $(this).next().show("slide", {
                        direction: "up"
                    }, 500);
                    $(this).addClass("tshow");
                }
                else
                {
                    $(this).next().hide();
                    $(this).removeClass("tshow");
                }
            });
        });
    });
</script>